package com.ftg.learn.rbac.mapper;

import com.ftg.learn.rbac.entity.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author kangjx
 * @since 2022-03-23
 */
@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {

    @Update("update sys_permission set title = #{title} where id = #{id}")
    boolean updateForName(@Param("id") int id, @Param("title") String title);

    /**
     * 当前角色 的所有权限
     * @param rid 角色编号
     * @return
     */
    @Select("select pid from sys_role_permission where rid = #{rid}")
    List<Integer> showMyself(@Param("rid") int rid);

    /**
     * 角色授权使用
     * @param rid
     */
    @Delete("delete from sys_role_permission where rid = #{rid}")
    void deleteRolePermission(@Param("rid")int rid);

    @Insert("insert into sys_role_permission(rid,pid) values(#{rid},#{pids})")
    void saveUserRole(@Param("rid") int rid,@Param("pids") Integer pids);
}
